package com.chen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.mapper.OrderMapper;
import com.chen.pojo.common.PageResult;
import com.chen.pojo.entry.Orders;
import com.chen.service.OrderService;
import com.chen.utils.PageUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * @author chen
 * @version 1.0
 * @create_date 2025/8/24
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public PageResult<Orders> searchList(Integer pageIndex, Integer pageSize,
                                         String orderNo, LocalDate start, LocalDate end) {
        Page<Orders> page = new Page<>(pageIndex, pageSize);
        LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(orderNo), Orders::getOrderNo, orderNo);
        wrapper.between(start != null && end != null, Orders::getCreateTime, start, end);
        page = orderMapper.selectPage(page, wrapper);
        return PageUtils.mapperResult(page);
    }
}
